class ReasetTileset {
  //重新渲染3dtiles
  reset(tileset) {
    return ReasetTileset.reset(tileset);
  }
  //递归将tile状态设置为过期
  expireTile(tile) {
    return ReasetTileset.expireTile(tile);
  }
  resetEffect() {
    ReasetTileset.resetEffect();
  }
  findTileset(url) {
    return ReasetTileset.findTileset(url);
  }
}
ReasetTileset.reset = (tileset) => {
  //主动调用渲染方法
  let tilesetPassState = new Cesium.Cesium3DTilePassState({
    pass: Cesium.Cesium3DTilePass.RENDER,
  });
  tileset.enableModelExperimental = true;
  tilesetPassState.camera = CIM.viewer.scene.camera;
  ReasetTileset.expireTile(tileset.root);
  tileset.updateForPass(CIM.viewer.scene.frameState, tilesetPassState);
  return tileset;
};
ReasetTileset.expireTile = (tile) => {
  let len = tile.children.length;
  if (len === 0) {
    tile._contentState = 0;
    tile.expireDate = Cesium.JulianDate.now();
  }
  for (let i = 0; i < len; i++) {
    ReasetTileset.expireTile(tile.children[i]);
  }
};
ReasetTileset.findTileset = (url) => {
  let tileset = CIM.viewer.scene.primitives._primitives.find((item) => {
    if (item instanceof Cesium.Cesium3DTileset && item._resource._url === url) {
      return item;
    }
  });
  return tileset;
};
ReasetTileset.resetEffect = () => {
  let primitives = CIM.viewer.scene.primitives._primitives;
  primitives.forEach((item) => {
    //销毁掉原先的设计方案
    if (item.customShader && item.customShader.design) {
      item.customShader.design.destroyed();
      item.customShader = undefined;
      ReasetTileset.reset(item);
    }
  });
};
export default new ReasetTileset();
